//
//  PickerImagesGridLayout.swift
//  MiaoleGB
//
//  Created by ET|冰琳 on 16/7/22.
//  Copyright © 2016年 UOKO. All rights reserved.
//

import UIKit

class PickerImagesGridLayout: LXReorderableCollectionViewFlowLayout {
    
    @IBInspectable var nums: Int = 4
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.setup()
    }
    
    override init() {
        super.init()
        self.setup()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    private func setup() {
        self.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10)
        self.minimumInteritemSpacing = 10
        let itemWidth: CGFloat = (UIScreen.main.bounds.width - 10 * CGFloat((self.nums + 1)))/CGFloat(self.nums)
        self.itemSize = CGSize(width: itemWidth, height: itemWidth)
    }
    
    override func prepare() {
        
        if let collection = self.collectionView {
            let itemWidth: CGFloat = (collection.frame.width - self.minimumInteritemSpacing * CGFloat(self.nums - 1) - self.sectionInset.left - self.sectionInset.right)/CGFloat(self.nums)
            self.itemSize = CGSize(width: itemWidth, height: itemWidth)
        }
        
        super.prepare()
        
    }

    override var collectionViewContentSize: CGSize {
        return super.collectionViewContentSize
    }
}
